home *** CD-ROM | disk | FTP | other *** search
/ Windows News 2010 Summer - Disc 1 / WN_Ete2010_CD1.iso / Onglet5 / Weezo / Weezo setup.exe / {code_appDir} / www / local / directLink.php < prev    next >
PHP Script  |  2010-05-19  |  46KB  |  1,102 lines

  1. <?php
  2. /**
  3.  * Direct file link generation an management
  4.  *
  5.  *
  6.  * PHP version 5
  7.  *
  8.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  9.  * that is available through the world-wide-web at the following URI:
  10.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  11.  * the PHP License and are unable to obtain it through the web, please
  12.  * send a note to license@php.net so we can mail you a copy immediately.
  13.  *
  14.  * @category   NA
  15.  * @package    NA
  16.  * @author     Nicolas Bruley / Peer 2 World <contact@weezo.net>
  17.  * @copyright  2005-2009 Nicolas Bruley / Peer 2 World
  18.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  19.  * @version    CVS: $Id:$
  20.  * @link       http://www.weezo.net
  21.  * @since      File available since Release 1.0.4
  22.  */
  23.  
  24.  
  25. /**
  26.  * @desc Verify external authentication is not set to on, and if so, display incompatibility message
  27.  *
  28.  * @param $type: 'directLink', 'publishDownload', 'publishImage', 'publishVideo', 'publishAudio'
  29.  */
  30. function dlCheckExternalAuth($type){
  31.     if(cfArrayItem(cfMGetVar('weezoRegInfo'),'externalAuth')){
  32.         $title=array('icon'=>'v','title'=>' ');
  33.         if(cfIsInApp() && $type!=='directLink') $title['title']=outButton(cfCaption('genBack'),"javascript:parent.slideFrame('publish','/local/uiResources/publish.php','up')",outIcon('backRed'),false,false,'style="position:absolute;right:0.5em"');
  34.         outDisplayErrorPage('<div class="extendedWarning" style="width:90%">'.cfCaption('externalAuthIncompatible').'</div><br>'.outButton(cfCaption('configAccountEdit'),"javascript:wl.UICommand('openprofile')",outIcon('logoSmall')),$title);
  35.     }
  36. }
  37.  
  38. /**
  39.  * @desc Return link URL
  40.  *
  41.  * @param string $id: item id
  42.  * @param array $tokenItem: item data
  43.  * @return string link
  44.  */
  45. function dlLinkURL($id,$tokenItem){
  46.     static $regInfo=false;
  47.  
  48.     if($tokenItem['type']=='directLink') return dlDirectLinkURL($id,$tokenItem);
  49.  
  50.     $link='<iframe frameborder="0" scrolling="no" src="'.dlDirectLinkURL($id,$tokenItem).'"';
  51.  
  52.     switch ($tokenItem['type']){
  53.         // Direct link / download
  54.         case 'publishDownload':
  55.             return $link.' style="width:220px;height:42px"></iframe>';
  56.         // Video
  57.         case 'publishVideo':
  58.             return $link.' frameborder="0" scrolling="no" style="width:'.$tokenItem['w'].'px;height:'.$tokenItem['h'].'px;background:black"></iframe>';
  59.         // Image
  60.         case 'publishImage':
  61.             return $link.' style="width:'.$tokenItem['w'].'px;height:'.$tokenItem['h'].'px;background:black"></iframe>';
  62.         // Audio
  63.         case 'publishAudio':
  64.             return $link.' style="width:252px;height:23px;background:black"></iframe>';
  65.     }
  66. }
  67.  
  68. /**
  69.  * @desc Return link URL
  70.  *
  71.  * @param string $id: item id
  72.  * @param array $tokenItem: item data
  73.  * @return string link
  74.  */
  75. function dlDirectLinkURL($id,$tokenItem){
  76.     static $regInfo=false;
  77.  
  78.     if(!$regInfo) $regInfo=cfMGetVar('weezoRegInfo');
  79.     if(!isset($regInfo['regName'])) return false;
  80.  
  81.     // Turn streaming direct link into published audio / video
  82.     if($tokenItem['type']=='directLink' && $tokenItem['downloadFormat']=='streaming') {
  83.         if(@$tokenItem['streaming']=='audio') $tokenItem['type']='publishAudio';
  84.         if(@$tokenItem['streaming']=='video') $tokenItem['type']='publishVideo';
  85.     }
  86.  
  87.     $link=DNS_SITE.'/embedded.php?userName='.$regInfo['regName'].'&type='.$tokenItem['type'].'&v='.cfGGetVar('appVersion');
  88.     if(isset($tokenItem['w'])) $link.='&w='.$tokenItem['w'].'&h='.$tokenItem['h'];
  89.     if(isset($tokenItem['autoplay'])) $link.='&autoplay='.(int)$tokenItem['autoplay'];
  90.     $link.='&uri=';
  91.     $encodedFilename=str_replace(' ','_',$tokenItem['filename']);
  92.  
  93.     switch ($tokenItem['type']){
  94.         // Direct link / download
  95.         case 'directLink':
  96.         case 'publishDownload':
  97.  
  98.             $dl=DNS_SITE.'/'.$regInfo['regName'].'/downloads/dlToken'.$id.'/';
  99.             // Torrent
  100.             if(isset($tokenItem['torrent'])) $dl.=cfFileWithoutExtension(basename($encodedFilename)).'.torrent';
  101.             // Zip or raw file
  102.             else $dl.=basename($encodedFilename).((is_dir($encodedFilename))?'.zip':'');
  103.  
  104.             if($tokenItem['type']=='directLink') return $dl; else return $link.$dl;
  105.  
  106.         // Video
  107.         case 'publishVideo':
  108.             return $link.('/video/dlToken.'.$id.'/file.'.basename($encodedFilename));
  109.         // Image
  110.         case 'publishImage':
  111.             return $link.('/img/dlToken.'.$id.'/file.'.cfUTF8Encode(basename($encodedFilename))).'&fullsizeAllowed='.((@$tokenItem['fullsizeAllowed'])?1:0);
  112.         // Audio
  113.         case 'publishAudio':
  114.             return $link.('/audio/dlToken.'.$id.'/file.playlist.xml');
  115.     }
  116. }
  117.  
  118. /**
  119.  * @display direct link management form
  120.  * @param $type: 'directLink' or 'publishDownload'
  121.  */
  122. function dlDirectLinkForm($type){
  123.  
  124.     // Verify that external authentication is disabled into profile, else display error message
  125.     if($type!=='directLink') dlCheckExternalAuth($type);
  126.  
  127.     require_once(INCLUDE_DIR.'explorerFunctions.php');
  128.     $presetFile=false; // prefil file/folder input with GET-passed file/folder name (base 64 encoded)
  129.     $synchronousTorrentGeneration=false; // Set to true to indicate a torrent is to be created, and that progres will be synchronously updated. Torrent is created just at the end of page display
  130.  
  131.     cfRCreateFakeResource();
  132.  
  133.     /**
  134.      * Read transfers tokens
  135.      */
  136.     $tokenList=efTokensRead();
  137.  
  138.     // Read registration info
  139.     $regInfo=cfMGetVar('weezoRegInfo');
  140.  
  141.     /**
  142.      * Thumbnail image
  143.      */
  144.     if(isset($_GET['thumbnailSrc'])){
  145.         header('Content-type: image/jpg');
  146.         header('Expires: '.gmdate("D, d M Y H:i:s",time()+3600*24*100).' GMT');
  147.         $file=base64_decode($_GET['thumbnailSrc']);
  148.         if(efFileType($file)=='image') cfCreateResizedJPG($file,0,0,'',$_GET['w'],$_GET['h']);
  149.         elseif(efFileType($file)=='video') efMakeVideoThumbnail($file,'',$_GET['w'],$_GET['h'],0,20);
  150.         exit;
  151.     }
  152.  
  153.     /**
  154.      * process POST
  155.      */
  156.     if(cfIsAsync()) cfAsyncHeader();
  157.     
  158.     // Update global direct links download speed limit
  159.     if(isset($_POST['directLinkDownloadSpeedLimitChange'])){
  160.         $sl=$_POST['directLinkDownloadSpeedLimitChange'];
  161.         if(!$sl) $sl=0;
  162.         if(is_numeric($sl) && $sl>=0 && $sl!==cfGGetVar('directLinkDownloadSpeedLimit')){
  163.             cfGUpdateVar('directLinkDownloadSpeedLimit',$sl,true);
  164.         }
  165.     }
  166.     
  167.     /**
  168.      * Direct link creation-related actions:
  169.      * Values: checkFile, checkFileAndCreate, create, browseFolder, browseFile, mailLink, suppressLink, abortBittorrentCreation
  170.      */
  171.     
  172.     if(isset($_POST['act'])){
  173.         $action=$_POST['act'];
  174.         if(isset($_POST['path'])) $_POST['path']=str_replace('\\','/',$_POST['path']);
  175.  
  176.         // Check file or folder's existance, and that it matches with type's files
  177.         if(($action=='checkFile'||$action=='checkFileAndCreate')){
  178.             if(!isset($_POST['path'])) $_POST['path']='';
  179.             $file=cfUTF8Decode($_POST['path'],true,false,false);
  180.  
  181.             // Check
  182.             if(strlen($file)>3 && file_exists($file) && (
  183.                     ($type=='directLink' || $type=='publishDownload') ||
  184.                     ($type=='publishAudio' && is_dir($file)) ||
  185.                     ($type=='publishImage' && is_file($file) && efFileType($file)=='image') ||
  186.                     ($type=='publishVideo' && is_file($file) && efFileType($file)=='video'))){}
  187.             // Check failed
  188.             else{
  189.                 echo cfAsyncXMLJSaction('dgi("path").style.color="red"');
  190.                 echo cfAsyncXMLJSaction("if(dgi('thumbnailLoading')) dgi('thumbnailLoading').style.display='none';");
  191.                 echo cfAsyncXMLJSaction('setThumbnailSrc(false)');
  192.                 echo cfAsyncXMLJSaction('wl.button.disable("createBt")');
  193.                 die(cfAsyncFooter());
  194.             }
  195.         }
  196.         // Sync submit page for actual creation
  197.         if($action=='checkFileAndCreate') {
  198.             echo cfAsyncXMLJSaction('proceedCreate()');
  199.             die(cfAsyncFooter());
  200.         }
  201.  
  202.         // Only check file: enable ok button, transmit image/video dimensions, reset path color
  203.         if($action=='checkFile'){
  204.             echo cfAsyncXMLJSaction('dgi("path").style.color=""');
  205.             switch ($type){
  206.                 case 'directLink':
  207.                     // Enable / disable streaming option depending on file type
  208.                     if(($mimeType=efFileType($file))=='audio' || $mimeType=='video')
  209.                         echo cfAsyncXMLJSaction('enableStreaming(1)');
  210.                     else
  211.                         echo cfAsyncXMLJSaction('enableStreaming(0)');
  212.  
  213.                     break;
  214.                 case 'publishVideo':
  215.                     require_once(INCLUDE_DIR.'viewVideoFunctions.php');
  216.                     list($w,$h)=vvfVideoDimensions($file);
  217.                 case 'publishImage':
  218.                     if($type=='publishImage') list($w, $h, $foo, $foo2) = @getimagesize($file);
  219.                     if(!$w){$w=200;$h=150;}
  220.                     echo cfAsyncXMLJSaction('setSourceDimensions('.$w.','.$h.')');
  221.                     list($rw,$rh)=cfThumbnailDimensions($w,$h,200,150,true);
  222.                     echo cfAsyncXMLJSaction('setThumbnailSrc("'.$_SERVER['PHP_SELF'].'?thumbnailSrc='.base64_encode($file).'&w='.$rw.'&h='.$rh.'",'.$rw.','.$rh.')');
  223.                     break;
  224.             }
  225.             echo cfAsyncXMLJSaction('wl.button.enable("createBt")');
  226.             die(cfAsyncFooter());
  227.         }
  228.  
  229.         // Browse files or folders
  230.         if($action=='browseFolder' || $action=='browseFile'){
  231.             // Browse files
  232.             if($action=='browseFile') $result= win_browse_file(true, '', '', null, array(cfUTF8Decode(cfCaption('genFile')) => "*.*"));
  233.             // Browse folders
  234.             else $result= $result= win_browse_folder('c:\\', cfUTF8Decode(cfCaption('genDirectory')));
  235.             cfAsyncHeader();
  236.             if($result) echo cfAsyncXMLJSaction('dgi("path").value="'.cfUTF8Encode(str_replace('\\','/',$result)).'"');
  237.             die(cfAsyncFooter());
  238.         }
  239.         // Send link by email
  240.         if($action=='mailLink' && isset($_POST['tokenId']) && isset($tokenList[$_POST['tokenId']])){
  241.             cfServerSendCommand('openMail body="'.dlDirectLinkURL($_POST['tokenId'],$tokenList[$_POST['tokenId']]).'" subject="'.basename(dlDirectLinkURL($_POST['tokenId'],$tokenList[$_POST['tokenId']])).'"');
  242.             cfAsyncHeader();
  243.             die(cfAsyncFooter());
  244.         }
  245.         // Remove existing link
  246.         if($action=='suppressLink' && isset($_POST['tokenId']) && isset($tokenList[$_POST['tokenId']])){
  247.             // If bittorrent transfer, remove from list
  248.             if($transferID=@$tokenList[$_POST['tokenId']]['torrentId']) {
  249.                 require_once(INCLUDE_DIR.'transferFunctions.php');
  250.                 tRemoveTransfer($transferID);
  251.             }
  252.             cfAsyncHeader();
  253.             unset($tokenList[$_POST['tokenId']]);
  254.             efTokensWrite($tokenList);
  255.             die(cfAsyncFooter());
  256.         }
  257.         // Abort bittorrent creation (done through this trick as bittorrent creation process doesn't detect connection abort)
  258.         if($action=='abortBittorrentCreation') cfMSetVar('weezoAbortBittorrentCreation',1);
  259.  
  260.         /**************************************
  261.          * Create new direct link (sync)
  262.          **************************************/
  263.         if($action=='create' && isset($_POST['type']) && cfIsRegistered()){
  264.             $type=$_POST['type'];
  265.             $token=array('type'=>$type);
  266.  
  267.             // Generate token ID
  268.             while (isset($tokenList[$tokenId=cfGenerateID(20)]));
  269.  
  270.             // Check source
  271.             if($type=='publishAudio' && isset($_POST['sharedMode']) && $_POST['sharedMode']=='list' && strlen($_POST['sharedItems'])){
  272.                 $token['filename']=cfUTF8Decode($_POST['sharedItems'],true,false,false,16000);
  273.             }
  274.             elseif (isset($_POST['path'])){
  275.                 if(!file_exists(cfUTF8Decode($_POST['path'],true,false,false))) die(cfAsyncFooter());
  276.                 $token['filename']=cfUTF8Decode($_POST['path'],true,false,false);
  277.             }
  278.             else die(cfAsyncFooter());
  279.  
  280.             // Direct link
  281.             if($type=='directLink'){
  282.                 if(!isset($_POST['lifetime']) || !is_numeric($_POST['lifetime'])) $_POST['lifetime']=1;
  283.                 if(!isset($_POST['maxDownloads']) || !is_numeric($_POST['maxDownloads'])) $_POST['maxDownloads']=1;
  284.                 //if(!isset($_POST['directLinkDownloadSpeedLimit']) || !is_numeric($_POST['directLinkDownloadSpeedLimit'])) $_POST['directLinkDownloadSpeedLimit']=cfGGetVar('directLinkDownloadSpeedLimit');
  285.                 if(isset($_POST['unlimitedDownloads'])) $token['limitNb']=0;
  286.                 else {
  287.                     $token['limitNb']=$_POST['maxDownloads'];
  288.                     $token['limitNbOriginal']=$_POST['maxDownloads'];
  289.                 }
  290.                 // lifetime
  291.                 if(isset($_POST['unlimitedLifetime']))$token['expiry']=0;
  292.                 else{
  293.                     if(!isset($_POST['lifetimePeriod'])) $_POST['lifetimePeriod']='days';
  294.                     if($_POST['lifetimePeriod']=='days') $token['expiry']=time() + $_POST['lifetime']*3600*24;
  295.                     elseif($_POST['lifetimePeriod']=='hours') $token['expiry']=time() + $_POST['lifetime']*3600;
  296.                     else $token['expiry']=time() + $_POST['lifetime']*60;
  297.                 }
  298.                 // Change max download speed if needed
  299.                 /*
  300.                 if($_POST['directLinkDownloadSpeedLimit']!=cfGGetVar('directLinkDownloadSpeedLimit'))
  301.                     cfGUpdateVar('directLinkDownloadSpeedLimit',$_POST['directLinkDownloadSpeedLimit']);
  302.                 */
  303.                 // Download format (zip/torrent/streaming)
  304.                 $token['downloadFormat']=((isset($_POST['downloadFormat']) && (
  305.                     $_POST['downloadFormat']=='zip' ||
  306.                     $_POST['downloadFormat']=='torrent' ||
  307.                     $_POST['downloadFormat']=='streaming'))?$_POST['downloadFormat']:'zip');
  308.                 cfGUpdateVar('directLinkDefaultFormat',$token['downloadFormat'],false);
  309.  
  310.                 // Streaming: set default size / reencoding values
  311.                 if(@$_POST['downloadFormat']=='streaming'){
  312.                     // Audio
  313.                     if(efFileType($token['filename'])=='audio') {
  314.                         $token['streaming']='audio';
  315.                         $token['maxOutputBitRate']='original';
  316.                     }
  317.                     // Video
  318.                     elseif(efFileType($token['filename'])=='video') {
  319.                         $token['streaming']='video';
  320.                         $token['flashOutputQuality']='original';
  321.                         // Width & height
  322.                         require_once(INCLUDE_DIR.'viewVideoFunctions.php');
  323.                         list($token['w'],$token['h'])=vvfVideoDimensions($token['filename']);
  324.                         if($token['w']==0){$token['w']=320;$token['h']=200;}
  325.                     }
  326.                     // Audio/video common
  327.                     $token['autoplay']=true;
  328.                 }
  329.             }
  330.  
  331.             // Downloads
  332.             elseif ($type=='publishDownload'){
  333.                 // Download format (zip/torrent)
  334.                 $token['downloadFormat']=((isset($_POST['downloadFormat']) && ($_POST['downloadFormat']=='zip'||$_POST['downloadFormat']=='torrent'))?$_POST['downloadFormat']:'zip');
  335.             }
  336.             // Audio files
  337.             elseif ($type=='publishAudio'){
  338.                 if(!isset($_POST['maxOutputBitRate']) || array_search($_POST['maxOutputBitRate'],array(32,64,128))===false) $token['maxOutputBitRate']='original';
  339.                 else $token['maxOutputBitRate']=$_POST['maxOutputBitRate'];
  340.                 $token['autoplay']=isset($_POST['autoplay']) && $_POST['autoplay']==='on';
  341.             }
  342.             // Images
  343.             elseif ($type=='publishImage'){
  344.                 // Width & height
  345.                 list($w,$h,$foo,$foo2) = @getimagesize($token['filename']);
  346.                 if($w==0){$w=320;$h=200;}
  347.                 if(isset($_POST['outputSize'])) $s=substr($_POST['outputSize'],0,strpos($_POST['outputSize'],' ')); else $s=$w;
  348.                 if(!is_numeric($s) || $s<=0 || $s>$w) $s=$w;
  349.                 $token['w']=$s; $token['h']=floor($s*$h/$w);
  350.                 // Full-size view allowed
  351.                 $token['fullsizeAllowed']=isset($_POST['fullsizeAllowed']) && $_POST['fullsizeAllowed']==='on';
  352.             }
  353.             // Videos
  354.             elseif ($type=='publishVideo'){
  355.                 // Width & height
  356.                 require_once(INCLUDE_DIR.'viewVideoFunctions.php');
  357.                 list($w,$h)=vvfVideoDimensions($token['filename']);
  358.                 if($w==0){$w=320;$h=200;}
  359.                 if(isset($_POST['outputSize'])) $s=substr($_POST['outputSize'],0,strpos($_POST['outputSize'],' ')); else $s=$w;
  360.                 if(!is_numeric($s) || $s<=0 || $s>$w) $s=$w;
  361.                 $token['w']=$s; $token['h']=floor($s*$h/$w);
  362.                 // Flash reencoding quality
  363.                 $token['flashOutputQuality']=$_POST['flashOutputQuality'];
  364.                 $token['autoplay']=isset($_POST['autoplay']) && $_POST['autoplay']==='on';
  365.             }
  366.  
  367.             if(!isset($token['limitNb'])) $token['limitNb']=0;
  368.  
  369.             // Torrent files: genrate torrent and add it to transfers
  370.             if(@$token['downloadFormat']=='torrent'){
  371.                 $synchronousTorrentGeneration=true;
  372.                 // Set created link so page display info popup on load, with empty link (so form won't be displayed immediately, but only once bittorrent is created)
  373.                 $createdLink=array('id'=>$tokenId,'link'=>'','directLink'=>'','token'=>$token);
  374.             }
  375.             // Set created link so page display info popup on load
  376.             else {
  377.                 $createdLink=array('id'=>$tokenId,'link'=>dlLinkURL($tokenId,$token),'directLink'=>dlDirectLinkURL($tokenId,$token),'token'=>$token);
  378.                 // Save tokens
  379.                 $tokenList+=array($tokenId=>$token);
  380.                 efTokensWrite($tokenList);
  381.             }
  382.         }
  383.     }
  384.     // End of $_POST processing
  385.  
  386.     if(cfIsAsync()) die(cfAsyncFooter());
  387.  
  388.  
  389.     // Preset file (passed from drag & drop over UI ?)
  390.     if (isset($_GET['presetFile']))    $presetFile=base64_decode($_GET['presetFile']);
  391.  
  392.     // File passed from Windows context menu
  393.     if(($shellExtFiles=cfGGetVar('uiResourceShellAction')) && cfGGetVar('uiResourceAccordion')=='send' && count($shellExtFiles)==1){
  394.         $presetFile=$shellExtFiles[0];
  395.         cfGSetVar('uiResourceShellAction',false,true);
  396.     }
  397.     elseif(($shellExtFiles=cfGGetVar('uiResourceShellFiles')) && cfGGetVar('uiResourceAccordion')=='publish'){
  398.         $presetFile=$shellExtFiles[0];
  399.         cfGSetVar('uiResourceShellFiles',false,true);
  400.     }
  401.  
  402.  
  403.     /**
  404.      * Display page
  405.      */
  406.     ob_start();
  407.     cfInsertHEAD(false);
  408.     echo cfScriptLink('winClient.js');
  409. ?>
  410. </HEAD>
  411. <body title="Weezo" onload="init()">
  412. <div id="mainDiv">
  413. <script type="text/javascript">
  414.  
  415. function init(){
  416.     if(dgi('createdLinkForm')) createdLinkFormShow();
  417. }
  418. function backKD(kc){
  419.     if(kc!==27 || !dgi("backButton")) return;
  420.     if(dgn('path') && dgn('path').value) return;
  421.     wl.removeKeycodeListener(D)
  422.     parent.slideFrame('publish','/local/uiResources/publish.php','up');
  423. }
  424. wl.setKeycodeListener(D,backKD)
  425.  
  426. // Change global direct link speed limit
  427. function directLinkDownloadSpeedLimitChange(n){
  428.     var v=n.value
  429.     if(v && (isNaN(n.value) || n.value<0)){
  430.         n.style.color='red';
  431.         return false;
  432.     }
  433.     else{
  434.         if(this.lastVal==undefined) this.lastVal=-1;
  435.         if(this.lastVal==v) return;
  436.         this.lastVal=n.value;
  437.         n.style.color='';
  438.         wl.asr.send({'directLinkDownloadSpeedLimitChange':v})
  439.     }
  440. }
  441.  
  442. var createdLinkFormShown=0;
  443. function createdLinkFormShow(){
  444.     maskShow(false,true);
  445.     var f=dgi('createdLinkForm');
  446.     f.style.display='';
  447.     $(f).e.center();
  448.     maskMoveAbove(f);
  449.     dgi('linkTA').select();
  450.     wl.setKeycodeListener(D,createdLinkFormShowKD)
  451.     createdLinkFormShown=1;
  452.     torrentProgressBarFade(false);
  453. }
  454. function createdLinkFormShowHide(){
  455.     if(createdLinkFormShown==0) return;
  456. <?php if($synchronousTorrentGeneration) echo 'wl.postData();';?>
  457.     var f=dgi('createdLinkForm');
  458.     fade(f,1,0);
  459.     maskHide();
  460.     createdLinkFormShown=0;
  461. }
  462. function createdLinkFormShowKD(kc){if(kc==13||kc==27) createdLinkFormShowHide()}
  463. function resizeWindow(){
  464.     return;
  465.     var h=dgi("mainDiv").offsetHeight+1*getElementStyle(D.body,'margin-top')+1*getElementStyle(D.body,'margin-bottom')+1*getElementStyle(D.body,'padding-top')+1*getElementStyle(D.body,'padding-bottom');
  466.     wl.UICommand('fadesize:0x'+Math.min(h+10,540))
  467. }
  468. var newLinkFormCollapseO;
  469. function newLinkFormCollapse(id,s){
  470.     if(s=='startFold') newLinkFormCollapseO=1;
  471.     if(s=='startUnfold') newLinkFormCollapseO=0;
  472.     if(s=='unfolding') newLinkFormCollapseO+=0.25;
  473.     if(s=='unfolding') newLinkFormCollapseO-=0.25;
  474.     setAlpha(dgi(id),Math.max(0,Math.min(1,newLinkFormCollapseO)));
  475. }
  476. function tabSelected(isSelected, tabName){
  477.     if(isSelected && tabName=='publish') D.location='/local/uiResources/publish.php';
  478. }
  479. function toggleUnlimitedLifetime(){
  480.     if(dgi("unlimitedLifetime").checked) {dgi("lifetime").disabled=true;dgi("lifetimePeriod").disabled=true;}
  481.     else{dgi("lifetime").disabled=false;dgi("lifetimePeriod").disabled=false;}
  482. }
  483. function toggleUnlimitedDownloads(){
  484.     if(dgi("unlimitedDownloads").checked) dgi("maxDownloads").disabled=true;
  485.     else dgi("maxDownloads").disabled=false;
  486. }
  487. function enableStreaming(enable){
  488.     dgi('streamingRadio').disabled=!enable;
  489.     dgi('streamingLabel').disabled=!enable;
  490.     if(!enable && dgi('streamingRadio').checked) dgn('downloadFormat').checked=true;
  491. }
  492. function checkFileAndCreate(){
  493.     dgi('act').value='checkFileAndCreate';
  494.     wl.button.setIcon('createBt','<?php echo outIcon('loading');?>');
  495.     wl.button.disable('createBt');
  496.     asyncSubmitForm("createForm",false);
  497.     if(dgi('cancelCreateBt')) {
  498.         dgi('cancelCreateBt').style.display='';
  499.         if(dgi('cancelBt')) dgi('cancelBt').style.display='none';
  500.         maskMoveAbove(dgi('cancelCreateBt'));
  501.     }
  502. }
  503. function cancelCreate(){
  504.     wl.asr.cancelAll();
  505.     windowStop();
  506.     wl.button.disable('createBt');
  507.     wl.button.setIcon('createBt','<?php echo outIcon('ok');?>');
  508.     dgi('cancelCreateBt').style.display='none';
  509.     if(dgi('cancelPresetBt')) dgi('cancelPresetBt').style.display='none';
  510.     torrentProgressBarFade(false);
  511.  
  512.     if(dgi('cancelBt')) dgi('cancelBt').style.display='';
  513.     sendData('act=abortBittorrentCreation');
  514.     maskHide();
  515. }
  516. function torrentProgressBarFade(fadeIn){
  517.     if(dgi('torrentProgressBar')) {
  518.         if(fadeIn){
  519.             dgi('torrentProgressBar').style.height='1px';
  520.             dgi('torrentProgressBar').style.display='';
  521.             fade('torrentProgressBar',0,1,30);
  522.             wl.fadeStyle('torrentProgressBar','height',20,'exponential',10);
  523.         }
  524.         else{
  525.             fade('torrentProgressBar',1,0,30);
  526.             wl.fadeStyle('torrentProgressBar','height',0,'exponential',10);
  527.         }
  528.     }
  529. }
  530. function proceedCreate(){
  531.     dgi('act').value='create';
  532.     try{D.createForm.submit();} catch(e){
  533.         alert(D.location.href)
  534.         try{D.location.href='http://google.fr';}
  535.         catch(e){wl.dbgObj(e)}
  536.  
  537.         if(0)try{wl.asr.send({'a':1},true)}
  538.         catch(e){wl.dbgObj(e)}
  539.         //asyncSubmitForm('createForm')
  540.     }
  541. }
  542. function browseFile(){
  543.     dgi('act').value='browseFile';
  544.     asyncSubmitForm("createForm",false);
  545. }
  546. function browseFolder(){
  547.     dgi('act').value='browseFolder';
  548.     asyncSubmitForm("createForm",false);
  549. }
  550. // Link suppression animation
  551. var suppressLinkId, suppressLinkHeight, suppressLinkI;
  552. function suppressLink(tokenId){
  553.     suppressLinkI=30;
  554.     suppressLinkId=tokenId;
  555.     dgi('linkFrame'+tokenId).style.overflow='hidden'
  556.     suppressLinkHeight=dgi('linkFrame'+tokenId).offsetHeight;
  557.     fade('linkFrame'+tokenId,1,0,suppressLinkI,'','suppressLinkShrink()');
  558.     dgi('activeLinksNb').innerHTML=dgi('activeLinksNb').innerHTML-1;
  559.     dgi('tokenId').value=tokenId;
  560.     dgi('act').value='suppressLink';
  561.     asyncSubmitForm("createForm",false);
  562. }
  563. function suppressLinkDone(){removeNode(dgi('linkFrame'+suppressLinkId))}
  564. function suppressLinkShrink(){
  565.     suppressLinkI--;
  566.     if(suppressLinkI>5) return;
  567.     dgi('linkFrame'+suppressLinkId).style.height=Math.max(1,Math.floor(suppressLinkHeight*suppressLinkI/15));
  568.     if(suppressLinkI<-10) suppressLinkDone()
  569.     else if(suppressLinkI<1) setTimeout('suppressLinkShrink()',10)
  570. }
  571. function mailLink(tokenId){sendData('tokenId='+tokenId+'&act=mailLink')}
  572. function showLink(tokenId){
  573.     if(dgi('ta'+tokenId).style.display=="inline"){
  574.         dgi('ta'+tokenId).style.display="none";
  575.     }
  576.     else{
  577.         dgi('ta'+tokenId).style.display="inline";
  578.         dgi('ta'+tokenId).select();
  579.     }
  580.     resizeWindow();
  581. }
  582. function pathChanged(){
  583.     if(!dgn("path").value) return;
  584.     if(dgi('thumbnailLoading')) dgi('thumbnailLoading').style.display='';
  585.     sendData('act=checkFile&path='+encodeURIComponent(dgn("path").value)+'&type=<?php echo $type;?>');
  586. }
  587. // required for rcSharedFilesBox
  588. function eSaveBt(varName,value){
  589.     //alert(varName+ ' '+value)
  590.     if(varName=='sharedMode') sharedMode_changed(value)
  591.     if(varName=='sharedMode' && value=='list') rcSharedFilesBoxUpdated(dgn('sharedItems').value)
  592.     if(varName=='path' || value=='folder') pathChanged();
  593. }
  594. // Called on file list modification
  595. function rcSharedFilesBoxUpdated(str){
  596.     if(str) wl.button.enable("createBt"); else wl.button.disable("createBt")
  597. }
  598. // Set source image/video dimensions
  599. var srcW,srcH;
  600. function setSourceDimensions(w,h){
  601.     srcW=w;srcH=h;
  602.     if(dgi('sourceSize')) dgi('sourceSize').innerHTML=w+' x '+h+' px';
  603.     if(dgi('sizeSel0')){
  604.         var i=0,sw,max=-1,maxi=0;
  605.         for(sw=160;sw<1600;sw*=2){
  606.             if(!dgi('sizeSel'+i)) break;
  607.             dgi('sizeVal'+i).innerHTML=sw+' x '+Math.floor(sw*h/w)+' px';
  608.             wl.blockItem('sizeSel'+i).enable(sw<=w);
  609.             if(sw<=w) {max=sw;maxi=i}
  610.             i++;
  611.         }
  612.  
  613.         if(max==-1) i=0;
  614.         else if(w==max) i=maxi;
  615.         else if(w>max) i=Math.min(maxi+1,i-1);
  616.         else i--;
  617.  
  618.         dgi('sizeVal'+i).innerHTML=w+' x '+h+' px';
  619.         wl.blockItem('sizeSel'+i).enable(1);
  620.  
  621.         for(i=0;i<10;i++){
  622.             if(!dgi('sizeSel'+i)||!wl.blockItem('sizeSel'+i).enabled()) break;
  623.             if(wl.blockItem('sizeSel'+i).selected()) return;
  624.         }
  625.         i--;
  626.         wl.blockItem('sizeSel'+i).select(1)
  627.         dgn('outputSize').value=dgi('sizeVal'+i).innerHTML;
  628.     }
  629. }
  630. var thumbnailHeight;
  631. // Set thumbail src
  632. function setThumbnailSrc(s,w,h){
  633.     if(!dgi("thumbnail")) return;
  634.     if(!s) s="<?php echo cfExtImage('foo',200,250);?>";
  635.     thumbnailHeight=h;
  636.     with(dgi("thumbnail")){
  637.         src=s
  638.         style.display='';
  639.         onload=thumbnailLoaded;
  640.     }
  641.  
  642.     var i=0;
  643.     while(dgi('sizeImg'+i)) {
  644.         with(dgi('sizeImg'+i)){
  645.             src=s;
  646.             if(srcW>srcH) {
  647.                 style.width=i*14+20;
  648.                 style.height=Math.floor((i*14+20)*srcH/srcW);
  649.                 style.marginTop=30-Math.floor((i*14+20)*srcH/2/srcW);
  650.             }
  651.             else{
  652.                 style.height=i*14+20;
  653.                 style.width=Math.floor((i*14+20)*srcW/srcH);
  654.                 style.marginTop=30-Math.floor((i*14+20)/2);
  655.             }
  656.         }
  657.         i++;
  658.     }
  659. }
  660. function thumbnailLoaded(){
  661.     dgi("thumbnail").style.width='';
  662.     dgi("thumbnail").style.height=thumbnailHeight;
  663.     if(dgi('thumbnailLoading')) dgi('thumbnailLoading').style.display='none';
  664. }
  665.  
  666. // Set BitTorrent encoding progress
  667. function setTorrentProgress(perc){
  668.     progressSetPerc('syncTorrentProgress',perc)
  669.     progressSetText('syncTorrentProgress',Math.floor(perc)+'%')
  670. }
  671. </script>
  672. <?php
  673.     //$createdLink=array('id'=>'5','link'=>'<qsdfqsf>','token'=>array('type'=>'publishD'));
  674.     if(isset($createdLink)){
  675. ?>
  676. <div id="createdLinkForm" style="position:absolute;display:none">
  677. <?php outShadowBefore('600');?>
  678. <div class="popup" style="position:static">
  679. <?php
  680.     echo '<div class="popupHeader">';
  681.     echo outImage(outIcon('ok'),false,false,'margin-right:0.5em;');
  682.     if($createdLink['token']['type']=='directLink') echo str_replace('<br>','</div><br>'.outButtonClipboardCopy('linkTA'), cfCaption('directLinkCreated'));
  683.     else echo cfCaption('publishLinkCreated').'</div>'.outButtonClipboardCopy('linkTA').cfCaption('publishLinkDescription');
  684.     echo "<br><br>\n";
  685.     echo '<center>';
  686.     echo '<textarea style="width:580px;height:4em" id="linkTA" onclick="this.select()" readonly="readonly">'.$createdLink['link'].'</textarea>';
  687.     echo '<br><br>';
  688.     if($createdLink['token']['type']!='directLink'){
  689.         echo '</center>';
  690.         echo outButtonClipboardCopy('directLinkTA').cfCaption('genLink').'<br>';
  691.         echo '<textarea style="width:580px;height:4em" id="directLinkTA" onclick="this.select()" readonly="readonly">'.$createdLink['directLink'].'</textarea><center>';
  692.         echo '<br><br>';
  693.     }
  694.     if($createdLink['token']['type']=='directLink') echo outButton(cfCaption('sendByMail'),'javascript:mailLink(\''.$createdLink['id'].'\')',outIcon('message'));
  695.     echo outButton(cfCaption('genOK'),'javascript:createdLinkFormShowHide()',outIcon('closeOK'));
  696.     echo '</center>';
  697.  
  698.     echo "</div>\n";
  699.     outShadowAfter();
  700.     echo "</div>\n";
  701. }
  702. ?>
  703. <form name="createForm" id="createForm" action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
  704. <input type="hidden" name="type" value="<?php echo $type;?>">
  705. <?php
  706.     echo outDivFrame('frame1');
  707.  
  708.     /***********************************************************************************
  709.      * Title, description, back button
  710.      ***********************************************************************************/
  711.  
  712.     // Direct link / BitTorrent
  713.     if($type=='directLink'){
  714.         $title=cfCaption('genDirectLink');
  715.         
  716.         $description='<span style="font-size:120%">'.cfCaption('directLinkExpl').'<br>'.cfCaption('directLinkExpl2').'</span>';
  717.                 // Speed limit
  718.         $sl=(int)cfGGetVar('directLinkDownloadSpeedLimit'); if(!$sl) $sl='';
  719.         $rightItem='<b>'.cfCaption('directLinkDownloadSpeedLimit').'<input class="textInput" type="text" id="directLinkDownloadSpeedLimit" name="directLinkDownloadSpeedLimit" style="width:3em;margin-left:1em;margin-right:1em;text-align:right" value="'.($sl).'" onchange="directLinkDownloadSpeedLimitChange(this)" onkeyup="directLinkDownloadSpeedLimitChange(this)" >'.cfCaption('explorerKBPS').'</b>';
  720.         $rightItem.=outButton('','javascript:var n=dgi(\'directLinkDownloadSpeedLimit\');n.value=\'\';directLinkDownloadSpeedLimitChange(n)',outIcon('infinite'),cfCaption('genUnlimited'),false,'style="margin-left:1em;margin-right:2em"');
  721.     }
  722.     // Published download / image / video / playlist
  723.     else{
  724.         $rightItem=outButton(cfCaption('genBack'),"javascript:parent.slideFrame('publish','/local/uiResources/publish.php','up')",outIcon('backRed'),false,'backButton');
  725.         $description=false;
  726.         $title=cfCaption($type.'Label');
  727.     }
  728.  
  729.     echo '<div style="float:right">'.$rightItem.'</div>';
  730.     echo '<div class="uiTabTitle">'.$title.'</div>';
  731.  
  732.     echo outDivFrame('','id="scrollDiv"','height:1;overflow:auto');
  733.  
  734.     // Description
  735.     if($description) echo '<div class="smallFont">'.$description.'</div><br>';
  736.  
  737.     // Error message
  738.     if(isset($errorMessage)) echo '<div class="warning">'.$errorMessage.'</div>';
  739.  
  740.  
  741.     /***********************************************************************************
  742.      * File(s) / folder selection
  743.      ***********************************************************************************/
  744.     echo outDivFrame('frame2');
  745.     echo '<div style="float:right">'.outButtonToggleCollapse('newLink',false,true,"'newLinkFormCollapse'").'</div>';
  746.     echo '<div class="frame2Header">'.outImageIcon('new').(($type=='directLink')?cfCaption('directLinkNew'):cfCaption('genNew'))."</div>\n";
  747.     // Collapsable frame
  748.     echo outCollapsableFrame('newLink',false,false,false);
  749.  
  750.     // File(s) / folder selection
  751.     if($type=='publishAudio'){
  752.         require_once(INCLUDE_DIR.'resourceConfigFunctions.php');
  753.         rcSharedFilesBox('audio',false,array('noDiv'=>1,'noSubDir'=>1,'noComputerRoot'=>1));
  754.     }
  755.     // Files selection list
  756.     else {
  757.         // Caption
  758.         echo (($type=='directLink'||$type=='publishDownload')?cfCaption('genFileOrFolder'):cfCaption('genFile')).cfCaption('genSeparator');
  759.         // <input>
  760.         echo '<input class="textInput" type="text" style="width:30em;margin-right:1em;vertical-align" name="path" id="path" onfocus="this.style.color=\'black\'"'.(($presetFile)?' value="'.cfUTF8Encode($presetFile).'"':'').' onkeyup="pathChanged(this.value)" onblur="pathChanged(this.value)">';
  761.  
  762.         echo '<input name="dropFileInput" onkeyup="if(this.value.indexOf(\'|\')!=-1) this.value=this.value.substr(0,this.value.indexOf(\'|\')); dgi(\'path\').value=this.value;pathChanged(this.value)" style="display:none">';
  763.  
  764.         // File/folder selection button
  765.         if(!$presetFile){
  766.             // Folder selection
  767.             if($type=='directLink'||$type=='publishDownload') echo outButton(cfCaption('genDirectory'),"javascript:wl.UICommand('openFolder','path')",outIcon('fi/folder'));
  768.  
  769.             // Filter (audio/video/image)
  770.             if($type=='publishImage') $fileTypeFilter='image';
  771.             elseif($type=='publishVideo') $fileTypeFilter='video';
  772.             else $fileTypeFilter=false;
  773.             if($fileTypeFilter) {
  774.                 require_once(INCLUDE_DIR.'mime_type.php');
  775.                 $extFilter=array();
  776.                 foreach ($_ENV['weezoMime'] as $ext=>$mime) if(cfCmpLeft($mime,$fileTypeFilter)) $extFilterArray[$ext]=$ext;
  777.                 $extFilter=':*.'.implode(';*.',$extFilterArray);
  778.             }
  779.             else $extFilter='';
  780.  
  781.             echo outButton(cfCaption('genFile'),"javascript:wl.UICommand('openFile".$extFilter."','path')",outIcon('blankFile'),false,'fileBt');
  782.         }
  783.         echo '<br><br>';
  784.     }
  785.  
  786.  
  787.  
  788.     /***********************************************************************************
  789.      * EXTRA PARAMETERS
  790.      ***********************************************************************************/
  791.  
  792.     // Download format (zip/bittorrent)
  793.     if($type=='directLink' || $type=='publishDownload'){
  794.         echo cfCaption('genFormat');
  795.         // ZIP
  796.         echo outImage(outIcon('fi/icoZip'),false,false,'vertical-align:middle;margin-right:0.5em;margin-left:3em');
  797.         echo '<input type="radio" name="downloadFormat" value="zip" style="vertical-align:middle"'.((cfGGetVar('directLinkDefaultFormat')!='torrent')?' checked="checked"':'').'><span onclick="this.previousSibling.checked=true" style="cursor:pointer">ZIP</span>';
  798.  
  799.         // Bittorrent
  800.         echo outImage(outIcon('bittorrent'),false,false,'vertical-align:middle;margin-right:0.5em;margin-left:3em');
  801.         echo '<input type="radio" name="downloadFormat" value="torrent" style="vertical-align:middle"'.((cfGGetVar('directLinkDefaultFormat')=='torrent')?' checked="checked"':'').'><span onclick="this.previousSibling.checked=true" style="cursor:pointer">'.cfCaption('bittorrent').'</span>';
  802.  
  803.         // Streaming
  804.         echo outImage(outIcon('play'),false,false,'vertical-align:middle;margin-right:0.5em;margin-left:3em');
  805.         echo '<input type="radio" name="downloadFormat" value="streaming" style="vertical-align:middle" disabled="true" id="streamingRadio"><span onclick="if(!this.previousSibling.disabled) this.previousSibling.checked=true" style="cursor:pointer" disabled="true" id="streamingLabel">Streaming</span>';
  806.         echo '<br>';
  807.     }
  808.  
  809.     // Direct link
  810.     if($type=='directLink'){
  811.         // Max downloads
  812.         echo cfCaption('directLinkLimitNb').'<input class="textInput" type="text" style="width:2em;margin-left:1em;text-align:right" value="1" name="maxDownloads" id="maxDownloads">';
  813.         echo '<input type="checkbox" name="unlimitedDownloads" id="unlimitedDownloads" style="margin-left:2em;margin-right:1em" onChange="toggleUnlimitedLifetime()" onclick="toggleUnlimitedDownloads()">'.cfCaption('genUnlimited').'<br><br>';
  814.  
  815.         // Lifetime
  816.         echo cfCaption('directLinkLifetime').'<input class="textInput" type="text" id="lifetime" name="lifetime" style="width:2em;margin-left:1em;margin-right:1em;text-align:right" value="1" disabled="disabled">';
  817.         echo '<select class="textInput" size="1" id="lifetimePeriod" name="lifetimePeriod" disabled="disabled">';
  818.         echo '<option selected="selected" value="days">'.cfCaption('genDays').'</option>';
  819.         echo '<option value="hours">'.cfCaption('genHours').'</option>';
  820.         echo '<option value="minutes">'.cfCaption('genMinutes').'</option>';
  821.         echo '</select>';
  822.         echo '<input type="checkbox" name="unlimitedLifetime" id="unlimitedLifetime" style="margin-left:2em;margin-right:1em" onChange="toggleUnlimitedLifetime()" onclick="toggleUnlimitedLifetime()" checked="checked">'.cfCaption('genUnlimited').'<br><br>';
  823.     }
  824.  
  825.     // Download
  826.     elseif ($type=='publishDownload'){
  827.         echo '<br>';
  828.     }
  829.  
  830.     // Video
  831.     elseif ($type=='publishVideo'){
  832.         // Thumbnail
  833.         echo '<table onclick="dgi(\'fileBt\').click()" class="frame3" style="cursor    :pointer;width:210;height:160;float:left;margin-right:1em;position:relative"><tr style="vertical-align:middle;height:100%"><td style="vertical-align:middle;height:100%;text-align:center"><img id="thumbnail" style="width:200px;height:150px" src="'.cfExtImage('foo',200,250).'"><img id="thumbnailLoading" style="position:absolute;left:50%;top:50%;margin-left:-8px;margin-top:-8px;display:none" src="'.outIcon('loadingBlack').'" alt=""></td></tr></table>';
  834.  
  835.         // Size selection
  836.         echo cfCaption('genSize').'<br>';
  837.         for($i=0;$i<4;$i++){
  838.             $c='<img id="sizeImg'.$i.'" style="position:relative;width:'.(($i)*12+20).';height:'.(($i)*9+15).';margin-top:'.floor(25-(($i)*9+15)/2).';background:black;border:1px solid #AAA" src="/ext/image.php">';
  839.             $c.='<div style="position:absolute;bottom:5;width:100;text-align:center;left:0" id="sizeVal'.$i.'">---</div>';
  840.             echo outBlockItem('sizeSel',$c,'id="sizeSel'.$i.'"','width:100;height:90;text-align:center;padding:5',array('onclick'=>"dgn('outputSize').value=dgi('sizeVal".$i."').innerHTML"),'disabled');
  841.         }
  842.         echo '<input name="outputSize" style="display:none">';
  843.  
  844.         // Flash output video quality
  845.         echo '<br><br>'.cfCaption('genQuality')."<br>\n";
  846.         ?>
  847. <select name="flashOutputQuality" class="textInput" size="1">
  848. <option selected="selected" value="original"><?php echo cfCaption('videoCfgSource');?></option>
  849. <option value="high"><?php echo cfCaption('genHigh');?></option>
  850. <option value="medium"><?php echo cfCaption('genMedium');?></option>
  851. <option value="low"><?php echo cfCaption('genLow');?></option>
  852. </select>
  853.    <input type="checkbox" name="autoplay"> <span onclick="dgn(\'autoplay\').checked=!dgn(\'autoplay\').checked" style="cursor:pointer"><?php echo cfCaption('autoplay');?></span>
  854. <?php
  855.         echo '<br clear="both">';
  856.     }
  857.  
  858.     // Image
  859.     elseif ($type=='publishImage'){
  860.         // Thumbnail
  861.         echo '<table onclick="dgi(\'fileBt\').click()" class="frame3" style="cursor:pointer;width:210;height:180;float:left;margin-right:1em;text-align:center"><tr style="vertical-align:middle;height:100%"><td style="vertical-align:middle;height:100%;text-align:center"><img id="thumbnail" style="width:200;height:150" src="'.cfExtImage('foo',200,250).'"></td></tr><tr><td id="sourceSize"> </td></tr></table>';
  862.  
  863.         // Size selection
  864.         echo cfCaption('genSize').'<br>';
  865.         for($i=0;$i<4;$i++){
  866.             $c='<img id="sizeImg'.$i.'" style="position:relative;width:'.(($i)*12+20).';height:'.(($i)*9+15).';margin-top:'.floor(25-(($i)*9+15)/2).';background:black;border:1px solid #AAA" src="/ext/image.php">';
  867.             $c.='<div style="position:absolute;bottom:5;width:100;text-align:center;left:0" id="sizeVal'.$i.'">---</div>';
  868.             echo outBlockItem('sizeSel',$c,'id="sizeSel'.$i.'"','width:100;height:90;text-align:center;padding:5',array('onclick'=>"dgn('outputSize').value=dgi('sizeVal".$i."').innerHTML"),'disabled');
  869.         }
  870.         echo '<input name="outputSize" style="display:none">';
  871.  
  872.         // Allow full-size image selection
  873.         echo '<br><br><br><input type="checkbox" checked="checked" name="fullsizeAllowed"> <span onclick="dgn(\'fullsizeAllowed\').checked=!dgn(\'fullsizeAllowed\').checked" style="cursor:pointer">'.cfCaption('explorerAllowFullSizeImage').'</span><br>';
  874.  
  875.         echo '<br clear="both">';
  876.     }
  877.  
  878.     // Audio
  879.     elseif ($type=='publishAudio'){
  880.         // Flash output video quality
  881.         echo cfCaption('genQuality').cfCaption('genSeparator');
  882.         ?>
  883. <select name="maxOutputBitRate" class="textInput" size="1">
  884. <option selected="selected" value="original"><?php echo cfCaption('musicCfgNoLimit');?></option>
  885. <option value="high"><?php echo cfCaption('explorerAudio128');?></option>
  886. <option value="medium"><?php echo cfCaption('explorerAudio64');?></option>
  887. <option value="low"><?php echo cfCaption('explorerAudio32');?></option>
  888. </select>
  889.    <input type="checkbox" name="autoplay"> <span onclick="dgn(\'autoplay\').checked=!dgn(\'autoplay\').checked" style="cursor:pointer"><?php echo cfCaption('autoplay');?></span>
  890. <?php
  891.     }
  892.  
  893.  
  894.     // Create / cancel buttons
  895.     echo '<br><center>';
  896.     echo outButton(cfCaption('adminResourceCreate'),'javascript:checkFileAndCreate()',outIcon('ok'),false,'createBt','style="margin-right:2em"',false,!$presetFile);
  897.     if($type!='directLink') echo outButton(cfCaption('genCancel'),"javascript:parent.slideFrame('publish','/local/uiResources/publish.php','up')",outIcon('cancel'),false,'cancelBt');
  898.     if($type=='directLink' || $type=='publishDownload') echo outButton(cfCaption('genCancel'),"javascript:cancelCreate()",outIcon('cancel'),false,'cancelCreateBt','style="display:none"');
  899.     if($type=='directLink' && $presetFile) echo outButton(cfCaption('genCancel'),"javascript:wl.postData()",outIcon('cancel'),false,'cancelPresetBt');
  900.  
  901.     if($synchronousTorrentGeneration) echo '<br><div id="torrentProgressBar" style="width:80%;padding:7px;overflow:hidden;display:none">'.outProgressBar(0,'100%','0%','syncTorrentProgress').'</div>';
  902.  
  903.     echo '</center><input type="hidden" value="" name="act" id="act"/>';
  904.     echo '<input type="hidden" value="" name="tokenId" id="tokenId"/>';
  905.     echo '</div>'; // Collapsable frame
  906.     echo "</div>\n"; // New link frame
  907.  
  908.  
  909.  
  910.     /****************************************************************************************************************************
  911.      * Display existing links
  912.      ****************************************************************************************************************************/
  913.     dlDisplayTokensLinks($type, $tokenList);
  914.     echo "</div>\n"; // scrollDiv
  915.     echo '</div></form>';
  916. ?>
  917. <script type="text/javascript">
  918. alignBottom(dgi('scrollDiv'),winMe,5);
  919. pathChanged();
  920. </script>
  921. </div>
  922. <?php
  923.  
  924.     /***********************************************************************************
  925.      * Unregistered user: display warning message
  926.      ***********************************************************************************/
  927.     if(!cfIsRegistered()){
  928. ?>
  929. <div id="regsitrationWarning" style="position:absolute;width:80%;left:10%;top:45%;padding-left:10%;padding-right:10%" class="extendedWarning"><br><?php echo outImage(outIcon('warning'),false,false,'float:left;margin-right:1em;margin-bottom:1em').cfCaption('registrationNeeded');?><br> </div>
  930. <script type="text/javascript">
  931. maskShow(true,true);
  932. maskMoveAbove(dgi('regsitrationWarning'));
  933. </script>
  934. <?php
  935.     }
  936.  
  937.  
  938.     ob_end_flush();
  939.  
  940.     /**
  941.      * Torrent files: genrate torrent and add it to transfers
  942.      */
  943.     if($synchronousTorrentGeneration){
  944.         wSession_write_close();
  945.         // Insert script tag so torrent synchronous javascript state updates are executed
  946.  
  947.         // Enable cancel button
  948.         echo "<script type=\"text/javascript\">dgi('cancelCreateBt').style.display='';wl.button.setIcon('createBt','".outIcon('loading')."');torrentProgressBarFade(true)</script>";
  949.         flush();
  950.         echo '<div style="position:absolute;top:0;left:0;background:red">';
  951.  
  952.         // Create torrent
  953.         list($token['torrentId'],$token['torrent'])=efTorrentCreate(array($token['filename']),$tokenId,array('jsSyncMonitorFunction'=>'setTorrentProgress'));
  954.  
  955.         // b64 encode torrent string to safely store it
  956.         $token['torrent']=base64_encode($token['torrent']);
  957.  
  958.         // Save tokens
  959.         $tokenList+=array($tokenId=>$token);
  960.         efTokensWrite($tokenList);
  961.  
  962.         // Set link into user popup (which will be displayed onload)
  963.         echo '<script type="text/javascript">';
  964.         echo 'setTorrentProgress(100);dgi("linkTA").innerHTML="'.dlDirectLinkURL($tokenId,$token).'";';
  965.         echo '</script>';
  966.     }
  967.     echo '</body></html>';
  968. }
  969.  
  970. /**
  971.  * @desc Display list of links from download/directLink/publishXXX tokens
  972.  *
  973.  * @param string $type: type of links to display:
  974.  *             false:all, "directLink", "download", "publishDownload", "publishVideo", "publishImage", "publishAudio"
  975.  */
  976. function dlDisplayTokensLinks($type='',&$tokenList=null){
  977.     if(!isset($tokenList)) $tokenList=efTokensRead();
  978.  
  979.     // Count active links
  980.     $nb=0; foreach ($tokenList as $value) if(!$type || $value['type']==$type) $nb++;
  981.  
  982.  
  983.     // Title
  984.     switch ($type){
  985.         case 'directLink':
  986.             $title=outImageIcon('directLink').cfCaption('directLinkList');
  987.             break;
  988.         case 'publishDownload':
  989.             $title=outImageIcon('dl2').cfCaption('publishDownloadLabel');
  990.             break;
  991.         default:
  992.             $title=cfCaption('publishExistingLinks');
  993.     }
  994.  
  995.     echo outDivFrame('frame2');
  996.     echo outFrameHeaderTable('frame2Header',$title,str_replace('%1','<span id="activeLinksNb">'.$nb.'</span>',cfCaption('publishActiveLinks')));
  997.  
  998.     // Display existing direct links
  999.     if($nb>0){
  1000.         foreach ($tokenList as $key=>$value) if(!$type || $value['type']==$type){
  1001.  
  1002.             echo outDivFrame('frame3','id="linkFrame'.$key.'"');
  1003.             // Link filename and suppress button
  1004.             $r='';
  1005.             switch ($value['type']){
  1006.                 case 'directLink':
  1007.                     $ico='directLink';
  1008.                     if(cfIsInApp()) $r.=outButtonSmall('','javascript:mailLink(\''.$key.'\')',outIcon('message'),cfCaption('sendByMail'));
  1009.                     break;
  1010.                 case 'directLink':
  1011.                     $ico='dl2';
  1012.                     break;
  1013.                 case 'download':
  1014.                     $ico='dl';
  1015.                     break;
  1016.             }
  1017.             // Suppress button
  1018.             $r.=outButtonSmall('','javascript:suppressLink(\''.$key.'\')',outIcon('cancel'),cfCaption('genDelete'));
  1019.  
  1020.             // link type icon
  1021.             //$l=outImage(outIcon($ico),false,false,'width:16;height:16;vertical-align:middle');
  1022.             $l='';
  1023.  
  1024.             // file type icon & filename
  1025.  
  1026.             // Torrent directLink and publishDownload
  1027.             if(@$value['downloadFormat']=='torrent') $l.=outImageIcon('bittorrent','title="'.cfCaption('bittorrent').'"');
  1028.  
  1029.             // Torrent directLink and publishDownload
  1030.             elseif(@$value['downloadFormat']=='streaming') $l.=outImageIcon('streaming','title="Streaming"');
  1031.  
  1032.             // Playlist: extract some filenames and put M3U icon
  1033.             if($type=='publishAudio' && !is_dir($value['filename'])){
  1034.                 $tmp='';
  1035.                 foreach (explode('|',$value['filename']) as $v){
  1036.                     $tmp.=', '.basename($v);
  1037.                     if(strlen($tmp)>100){$tmp=cfStrTruncate($tmp,100);break;}
  1038.                 }
  1039.                 $l.=outImageIcon('/fi/icoM3u').cfUTF8Encode(substr($tmp,2));
  1040.             }
  1041.             // Others: display file's icon & complete filename
  1042.             else $l.=outImage(efIcon($value['filename']),false,false,'width:16;height:16;vertical-align:middle;margin-right:0.3em').cfUTF8Encode(basename($value['filename']).' ('.dirname($value['filename']).')');
  1043.  
  1044.             //if(isset($value['size']) && $value['size']) $l.=' ('.$value['size'].')';
  1045.  
  1046.             echo outFrameHeaderTable('frame3Header',$l,$r);
  1047.  
  1048.             // Embed code snippet
  1049.             if($type!=='directLink'){
  1050.                 echo '<span style="float:left;margin-top:2;font-weight:bold;width:8em">'.cfCaption('linkCode').cfCaption('genSeparator').'</span>';
  1051.                 echo '<span style="float:right;margin-top:2;margin-left:1em">'.outButtonSmall('','javascript:wl.clipboardCopy(\'ta'.$key.'\')',outIcon('paste'),cfCaption('genCopy')).'</span>';
  1052.                 echo '<input id="ta'.$key.'" class="textinput" style="width:100%" onclick="this.select();return true" value="'.str_replace('"','"',cfUTF8Encode(dlLinkURL($key,$value))).'">';
  1053.                 echo '<br clear="all">';
  1054.             }
  1055.  
  1056.             // LINK
  1057.             echo '<span style="float:left;margin-top:2;font-weight:bold;width:8em">'.cfCaption('genLink').cfCaption('genSeparator').'</span>';
  1058.             echo '<span style="float:right;margin-top:2;margin-left:1em">'.outButtonSmall('','javascript:wl.clipboardCopy(\'tb'.$key.'\')',outIcon('paste'),cfCaption('genCopy')).'</span>';
  1059.             echo '<input id="tb'.$key.'" class="textinput" style="width:100%" onclick="this.select();return true" value="'.str_replace('"','"',cfUTF8Encode(dlDirectLinkURL($key,$value))).'">';
  1060.  
  1061.             // Link lifetime
  1062.             if($value['type']=='directLink'){
  1063.                 echo cfCaption('directLinkLifetime').cfCaption('genSeparator');
  1064.                 if($value['expiry']==0) echo cfCaption('genUnlimited'); else echo date(cfCaption('_FILE_DATE_FORMAT'),$value['expiry']);
  1065.             }
  1066.  
  1067.             $l='';
  1068.             // Max downloads number
  1069.             if($value['type']=='directLink'){
  1070.                 $l.=cfCaption('directLinkLimitNb').cfCaption('genSeparator');
  1071.                 if($value['limitNb']<=0) $l.=cfCaption('genUnlimited'); else $l.=cfUTF8Encode($value['limitNbOriginal']);
  1072.             }
  1073.             // Videos
  1074.             elseif($value['type']=='publishVideo'){
  1075.                 $l.=cfCaption('genSize').cfCaption('genSeparator').$value['w'].'x'.$value['h'].' - '.cfCaption('genQuality').cfCaption('genSeparator');
  1076.                 $tmp=array("original"=>cfCaption('videoCfgSource'),"high"=>cfCaption('genHigh'),"medium"=>cfCaption('genMedium'),"low"=>cfCaption('genLow'));
  1077.                 $l.=$tmp[$value['flashOutputQuality']];
  1078.             }
  1079.             // Images
  1080.             elseif($value['type']=='publishImage'){
  1081.                 $l.=cfCaption('genSize').cfCaption('genSeparator').$value['w'].'x'.$value['h'];
  1082.             }
  1083.             // Audio
  1084.             elseif($value['type']=='publishAudio'){
  1085.                 $l.='';
  1086.             }
  1087.  
  1088.  
  1089.             // Completed downloads
  1090.             $r=cfCaption('directLinkCompletedDl').cfCaption('genSeparator');
  1091.             if($value['limitNb']<=0) $nb=(0-$value['limitNb']); else $nb=$value['limitNbOriginal']-$value['limitNb'];
  1092.             if($nb==0) $r.=$nb; else $r='<b>'.$r.$nb.'</b>';
  1093.             if($l) echo outFrameFooterTable('',$l,$r);
  1094.             else echo '<br>'.$r;
  1095.  
  1096.             echo "</div>\n";
  1097.         }
  1098.     }
  1099.     else echo '<br>';
  1100.     echo '</div>';
  1101. }
  1102. ?>